package org.jsola.hr.service.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;
import org.jsola.common.BeanKit;
import org.jsola.hr.dto.excel.AttendPunchRecordImportDTO;
import org.jsola.hr.dto.excel.CrmCustomerImportDTO;
import org.jsola.hr.entity.AttendPlanDO;
import org.jsola.hr.entity.EmpInfoDO;
import org.jsola.hr.exception.HrException;
import org.jsola.hr.query.EmpInfoQuery;
import org.jsola.hr.service.IAttendPlanService;
import org.jsola.hr.service.IAttendPunchRecordService;
import org.jsola.hr.service.IEmpInfoService;
import org.jsola.hr.vo.excel.ParseResultVO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zdd
 */
@Slf4j
public class CrmCustomerImportListener extends AnalysisEventListener<Map<Integer, String>> {
    List<CrmCustomerImportDTO> list = new ArrayList();

    public List<CrmCustomerImportDTO> getList() {
        return list;
    }

    @Override
    public void invoke(Map<Integer, String> data, AnalysisContext context) {
        if(list.size() >= 500){
            return;
        }
        CrmCustomerImportDTO crmCustomerImportDTO = new CrmCustomerImportDTO();
        for (int i = 0; i < data.size(); i++) {
            if(i==0){
                crmCustomerImportDTO.setName(data.get(i));
            }else if(i == 1){
                crmCustomerImportDTO.setPhone(data.get(i));
            }else if(i == 2){
                if("男".equals(data.get(i))){
                    crmCustomerImportDTO.setGender(1);
                }else if("女".equals(data.get(i))){
                    crmCustomerImportDTO.setGender(2);
                }
            }else if(i == 3){
                crmCustomerImportDTO.setEmail(data.get(i));
            }else if(i == 4){
                crmCustomerImportDTO.setWechat(data.get(i));
            }else if(i == 5){
                crmCustomerImportDTO.setPostName(data.get(i));
            }else if(i == 6){
                crmCustomerImportDTO.setCompanyName(data.get(i));
            }else if(i == 7){
                crmCustomerImportDTO.setCompanyAddress(data.get(i));
            }else if(i == 8){
                if(data.get(i) != null){
                    if("有限责任".equals(data.get(i))){
                        crmCustomerImportDTO.setCompanyType(1);
                    }else if("个人独资".equals(data.get(i))){
                        crmCustomerImportDTO.setCompanyType(2);
                    }else if("股权有限责任".equals(data.get(i))){
                        crmCustomerImportDTO.setCompanyType(3);
                    }else if("其他".equals(data.get(i))){
                        crmCustomerImportDTO.setCompanyType(4);
                    }

                }
            }else if(i == 9){
                if("500以下".equals(data.get(i))){
                    crmCustomerImportDTO.setCompanyPersonSize(1);
                }else if("500-1000".equals(data.get(i))){
                    crmCustomerImportDTO.setCompanyPersonSize(2);
                }else if("1000-3000".equals(data.get(i))){
                    crmCustomerImportDTO.setCompanyPersonSize(3);
                }else if("3000以上".equals(data.get(i))){
                    crmCustomerImportDTO.setCompanyPersonSize(4);
                }
            }
        }
        list.add(crmCustomerImportDTO);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}